#!/bin/sh /etc/rc.common

START=97

USE_PROCD=1
NAME=uftpd
PROG=/sbin/uftpd


udisk_dir="/mnt/sda1"
store_path="/Storage/Plat/Article/"

start_service() {
echo "step_0" >> /tmp/uftpdlog.txt
uflag=`df | grep $udisk_dir`
echo "step_1" >> /tmp/uftpdlog.txt
if [ -z "$uflag" ]; then
	mkdir -p /mnt/sda1
        mount /dev/sda1 /mnt/sda1
        echo "step_2" >> /tmp/uftpdlog.txt
        sleep 1
fi
echo "step_3" >> /tmp/uftpdlog.txt                        
uflag=`df | grep $udisk_dir`

echo "step_4" >> /tmp/uftpdlog.txt
if [ -z "$uflag" ]; then
	echo "step_4_exit" >> /tmp/uftpdlog.txt
	exit
fi
echo "step_5" >> /tmp/uftpdlog.txt
mkdir -p /var/lib/nginx/
mkdir -p /var/log/nginx/

echo "step_6" >> /tmp/uftpdlog.txt
echo "step_6 condition is ${udisk_dir}${store_path}" >> /tmp/uftpdlog.txt
if [ ! -d ${udisk_dir}${store_path} ]; then
	mkdir  -p ${udisk_dir}${store_path}
	echo "step_6 mkdir" >> /tmp/uftpdlog.txt
	
fi
#uftpd -D /mnt/sda1 -M 225.0.0.25 - c 20971520 -t -B 8053600 -q
sleep 5
echo "step_7" >> /tmp/uftpdlog.txt
echo "step_7 cmd is uftpd -D ${udisk_dir} -M 225.0.0.25 -c 20971520 -t -B 8053600 -f /usr/sbin/adjust.lua  -q" >> /tmp/uftpdlog.txt
uftpd   -D ${udisk_dir} -M 225.0.0.25 -t -B 8053600 -f /usr/sbin/adjust.lua  -q
echo "step_8" >> /tmp/uftpdlog.txt
if [ ! -d "/var/log/nginx"  ]; then
	mkdir -p /var/log/nginx/
	echo "step_8 mkdir" >> /tmp/uftpdlog.txt
fi
echo "step_9" >> /tmp/uftpdlog.txt
if [ ! -d "/var/lib/nginx" ]; then
	mkdir -p /var/lib/nginx/
	echo "step_9 mkdir" >> /tmp/uftpdlog.txt
fi
echo "step_10" >> /tmp/uftpdlog.txt
nginx -c /etc/nginx/uftp.conf
echo "step_11" >> /tmp/uftpdlog.txt
cp /etc/nginx/auth.sqlite /tmp
chmod 666 /tmp/auth.sqlite   
echo "step_11_cp" >> /tmp/uftpdlog.txt  
##/usr/sbin/check_disk.lua &

                                       
                                                                                             
                                                                                             

}





stop_service() {
#       nginx_pid=`cat /tmp/nac_https_nginx.pid`
#       [ $? -eq 0 ] && [ -n $nginx_pid ] && kill -9 $nginx_pid &&  kill -9 $(($nginx_pid+1));
echo "step_12_stop" >> /tmp/uftpdlog.txt
if [ -e "/var/run/nginx_uftp.pid" ]; then
	nginx -c /etc/nginx/uftp.conf  -s stop
fi
killall  -9  uftpd
echo "step_13_kill" >> /tmp/uftpdlog.txt
  

}



restart() {

        stop_service  
        start_service 
}


